#!/bin/bash
CONFIG=$1

IF_NAME=$(echo ${CONFIG} |cut -d '.' -f 1 )
IF_PKEY=$(echo ${CONFIG} |cut -d '.' -f 2 -s)

echo ${IF_NAME} | grep ^ifcfg-  >/dev/null 2>&1 
if [ "$?" = "0" ] ; then
   IF_NAME=$(echo ${IF_NAME} |cut -d '-' -f 2 )
fi


#Check if the device name is ib0, ib1 etc.
echo ${IF_NAME} | grep ^ib  >/dev/null 2>&1 
if [ "$?" = "1" ] ; then
   exit 1
fi

if [ -z ${IF_PKEY} ]; then
   exit 1
fi


if [ -e /sys/class/net/${IF_NAME}/create_child ]; then
   if [ ! -e /sys/class/net/${IF_NAME}.$IF_PKEY ] ; then
	   echo 0x$IF_PKEY > /sys/class/net/${IF_NAME}/create_child
   fi
fi
exit 0
